Also remove redundant 'new Promise' indirection, in favour
of native chaining through "then()".
This avoids a situation where wdio could hang indefinitely (until
timeout) when MWBot.request fails because we did not attach any
"catch()" handler to the promise. By always keeping a chain, the
failures are (by default) forwarded and thus propagated and thus
caught eventually.
Change-Id: If2f09479600029db2fa967c57082031744a06d8f
const MWBot = require( 'mwbot' ),
Page = require( './Page' ),
const MWBot = require( 'mwbot' ),
Page = require( './Page' ),
- FRONTPAGE_REQUESTS_MAX_RUNS = 10; // (arbitrary) safe-guard against endless execution
+ MAINPAGE_REQUESTS_MAX_RUNS = 10; // (arbitrary) safe-guard against endless execution
function getJobCount() {
let bot = new MWBot( {
apiUrl: `${browser.options.baseUrl}/api.php`
} );
function getJobCount() {
let bot = new MWBot( {
apiUrl: `${browser.options.baseUrl}/api.php`
} );
- return new Promise( ( resolve ) => {
- return bot.request( {
- action: 'query',
- meta: 'siteinfo',
- siprop: 'statistics'
- } ).then( ( response ) => {
- resolve( response.query.statistics.jobs );
- } );
+ return bot.request( {
+ action: 'query',
+ meta: 'siteinfo',
+ siprop: 'statistics'
+ } ).then( ( response ) => {
+ return response.query.statistics.jobs;
process.stdout.write( `RunJobs ${message}\n` );
}
process.stdout.write( `RunJobs ${message}\n` );
}
-function runThroughFrontPageRequests( runCount = 1 ) {
+function runThroughMainPageRequests( runCount = 1 ) {
- log( `through requests to the front page (run ${runCount}).` );
+ log( `through requests to the main page (run ${runCount}).` );
return;
}
log( `detected ${jobCount} more queued job(s).` );
return;
}
log( `detected ${jobCount} more queued job(s).` );
- if ( runCount >= FRONTPAGE_REQUESTS_MAX_RUNS ) {
- log( 'stopping requests to the front page due to reached limit.' );
+ if ( runCount >= MAINPAGE_REQUESTS_MAX_RUNS ) {
+ log( 'stopping requests to the main page due to reached limit.' );
- return runThroughFrontPageRequests( ++runCount );
+ return runThroughMainPageRequests( ++runCount );
static run() {
browser.call( () => {
static run() {
browser.call( () => {
- return runThroughFrontPageRequests();
+ return runThroughMainPageRequests();